/*
 * @Description: 
 * @Author: Aroma
 * @Date: 2024-10-08 09:48:55
 * @LastEditors: Aroma
 * @LastEditTime: 2024-10-08 19:53:04
 * @别瞎看: 你个无脑牛马
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


class PokerGame {
    private List<Card> deck;

    public PokerGame() {
        // 初始化牌组
        deck = new ArrayList<>();
        String[] suits = {"♥", "♠", "♣", "♦"};
        String[] values = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
        for (String suit : suits) {
            for (String value : values) {
                deck.add(new Card(suit, value));
            }
        }
        deck.add(new Card("", "小王"));
        deck.add(new Card("", "大王"));
    }

    // 洗牌
    public void shuffle() {
        Collections.shuffle(deck);
    }

    // 发牌
    public List<List<Card>> dealCards() {
        List<List<Card>> hands = new ArrayList<>();
        List<Card> bottomCards = new ArrayList<>();

        // 先发底牌
        for (int i = 0; i < 3; i++) {
            bottomCards.add(deck.remove(deck.size() - 1));
        }

        // 玩家牌
        for (int i = 0; i < 3; i++) {
            List<Card> hand = new ArrayList<>();
            for (int j = 0; j < 17; j++) {
                hand.add(deck.remove(0));
            }
            hands.add(hand);
        }

        hands.add(bottomCards); // 将底牌作为第四个列表添加，虽然通常不显示给玩家

        return hands;
    }

    // 显示牌面（仅用于演示，实际游戏中可能不需要这样显示）
    public void printCards(List<List<Card>> hands) {
        System.out.println("底牌：");
        for (Card card : hands.get(3)) {
            System.out.print(card + " ");
        }
        System.out.println();

        for (int i = 0; i < 3; i++) {
            System.out.print("玩家" + (i + 1) + "：");
            Collections.sort(hands.get(i), (c1, c2) -> {
                if (!c1.suit.equals(c2.suit)) {
                    return c1.suit.compareTo(c2.suit);
                }
                return c1.value.compareTo(c2.value);
            });
            for (Card card : hands.get(i)) {
                System.out.print(card + " ");
            }
            System.out.println();
        }
    }
}
